package com.zhzh.StudySpringBoot.web;

import com.zhzh.StudySpringBoot.service.BlogProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2017/11/8.
 */
@Controller
public class HelloController {

    @Autowired
    private BlogProperties blogProperties;

    @RequestMapping("/helloo")
    public String findex() throws Exception {
        System.out.println("zz--------------"+blogProperties.getName());
        System.out.println("zz--------------"+blogProperties.getValue());
        return "Hello World";
    }

    @RequestMapping("/")
    public String index() {
        return "index";
    }

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() {
        return "login";
    }

    @RequestMapping("/testError")
    public String error() throws Exception {
        System.out.println("enter error");
        throw new Exception("发生错误");
    }

    @RequestMapping("/velocity")
    public String index(ModelMap map) {
        // 加入一个属性，用来在模板中读取
        map.addAttribute("host", "http://blog.didispace.com");
        System.out.println("velocity");
        return "velocity";
    }

    @RequestMapping("/thymeleaf")
    public String TestThymeleaf(ModelMap map) {
        // 加入一个属性，用来在模板中读取
        map.addAttribute("host", "http://blog.didispace.com");
        System.out.println("TestThymeleaf");
        return "thymeleaf";
    }

    @RequestMapping("/freemarker")
    public String Freemarker(ModelMap map) {
        // 加入一个属性，用来在模板中读取
        map.addAttribute("host", "http://blog.didispace.com");
        System.out.println("Freemarker");
        return "freemarker";
    }
}
